package com.tairan.chapter.flowable.controller;

import com.github.pagehelper.PageInfo;
import com.tairan.chapter.flowable.model.Flow;
import com.tairan.chapter.flowable.service.FlowTaskService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/act/task")
public class FlowTaskController {

    @Autowired
    private FlowTaskService flowTaskService;

    @RequestMapping(value = "/diagramViewer")
    public String diagramViewer(String definitionId, String instanceId, String hisInsId, Model model) {

        model.addAttribute("definitionId", StringUtils.isBlank(definitionId) ? "" : definitionId);
        model.addAttribute("instanceId", StringUtils.isBlank(instanceId) ? "" : instanceId);
        model.addAttribute("hisInsId", StringUtils.isBlank(hisInsId) ? "" : hisInsId);

        return "flow/flowDiagramViewer";
    }

    @RequestMapping({"todo", ""})
    @ResponseBody
    public Object todoList(String userId) {
        PageInfo<Flow> pageInfo = flowTaskService.todoList(userId);
        return pageInfo;
    }
}
